package myApp.mobile;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Environment;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.sql.Timestamp;
import java.util.Date;
import myApp.classi.Connection;

public class Home extends Activity
{
  static TextView timeDisplay;
  static long timeRemaining = 0L;
  boolean controllo;
  MyCount counter;
  boolean timeRun = false;

  private Bitmap encodeString(String paramString)
  {
    try
    {
      URLConnection localURLConnection = new URL("http://qrcode.kaywa.com/img.php?s=8&d=" + paramString).openConnection();
      localURLConnection.connect();
      InputStream localInputStream = localURLConnection.getInputStream();
      BufferedInputStream localBufferedInputStream = new BufferedInputStream(localInputStream);
      Bitmap localBitmap2 = BitmapFactory.decodeStream(localBufferedInputStream);
      localBufferedInputStream.close();
      localInputStream.close();
      localBitmap1 = localBitmap2;
      return localBitmap1;
    }
    catch (MalformedURLException localMalformedURLException)
    {
      while (true)
      {
        localMalformedURLException.printStackTrace();
        Bitmap localBitmap1 = null;
      }
    }
    catch (IOException localIOException)
    {
      while (true)
        localIOException.printStackTrace();
    }
  }

  public static String formatTime(long paramLong)
  {
    long l1 = paramLong / 1000L;
    long l2 = l1 / 60L;
    long l3 = l2 / 60L;
    long l4 = l3 / 24L;
    long l5 = l1 % 60L;
    long l6 = l2 % 60L;
    long l7 = l3 % 24L;
    String str1 = String.valueOf(l5);
    String str2 = String.valueOf(l6);
    String str3 = String.valueOf(l7);
    if (l5 < 10L);
    for (String str4 = "0" + l5; ; str4 = str1)
    {
      if (l6 < 10L);
      for (String str5 = "0" + l6; ; str5 = str2)
      {
        if (l7 < 10L);
        for (String str6 = "0" + l7; ; str6 = str3)
        {
          if (l4 > 0L);
          for (String str7 = l4 + "d "; ; str7 = "")
            return str7 + str6 + ":" + str5 + ":" + str4;
        }
      }
    }
  }

  public void exit()
  {
    File localFile = Environment.getExternalStorageDirectory();
    if (localFile.canWrite())
      new File(localFile, "mBusData.txt").delete();
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903042);
    Button localButton1 = (Button)findViewById(2131165188);
    Button localButton2 = (Button)findViewById(2131165194);
    final Connection localConnection = new Connection();
    timeDisplay = (TextView)findViewById(2131165195);
    TextView localTextView1 = (TextView)findViewById(2131165192);
    TextView localTextView2 = (TextView)findViewById(2131165193);
    TextView localTextView3 = (TextView)findViewById(2131165191);
    ImageView localImageView = (ImageView)findViewById(2131165196);
    String str1 = "";
    localImageView.setBackgroundColor(-16777216);
    timeDisplay.setTextColor(-16777216);
    try
    {
      File localFile1 = Environment.getExternalStorageDirectory();
      if (localFile1.canWrite())
      {
        File localFile2 = new File(localFile1, "mBusData.txt");
        FileReader localFileReader = new FileReader(localFile2);
        BufferedReader localBufferedReader = new BufferedReader(localFileReader);
        str1 = localBufferedReader.readLine();
        str1 = str1.split("!i!")[0];
        localButton1.setText("Buy " + localConnection.getCategory(str1));
        localBufferedReader.close();
      }
      localTextView1.setTextColor(-16711936);
      localTextView3.setTextColor(-16711936);
      localTextView3.setText(str1);
      String str2 = localConnection.getValidTicket(str1);
      if (!str2.equals("NO DATA"))
      {
        String[] arrayOfString = str2.split("!i!");
        String str3 = arrayOfString[0];
        String str4 = arrayOfString[1];
        localImageView.setImageBitmap(encodeString(str3));
        Date localDate = new Date();
        Timestamp localTimestamp1 = Timestamp.valueOf(str4);
        Timestamp localTimestamp2 = new Timestamp(localDate.getTime());
        long l = localTimestamp1.getTime() - localTimestamp2.getTime();
        if (this.timeRun)
        {
          this.counter.stop();
          this.counter.cancel();
          this.timeRun = false;
        }
        this.counter = null;
        MyCount localMyCount = new MyCount(l, 1000L);
        this.counter = localMyCount;
        start(timeDisplay);
        timeDisplay.setTextColor(-1);
        this.timeRun = true;
        localTextView1.setText(str3);
        localTextView2.setText("Valid for: ");
        this.controllo = false;
        View.OnClickListener local1 = new View.OnClickListener()
        {
          public void onClick(View paramAnonymousView)
          {
            Intent localIntent = new Intent();
            localIntent.setClass(Home.this, Valid.class);
            Home.this.startActivity(localIntent);
          }
        };
        localButton2.setOnClickListener(local1);
        View.OnClickListener local2 = new View.OnClickListener()
        {
          public void onClick(View paramAnonymousView)
          {
            String str;
            Context localContext;
            if (Home.this.controllo)
            {
              str = "";
              localContext = Home.this.getApplicationContext();
            }
            while (true)
            {
              try
              {
                File localFile = Environment.getExternalStorageDirectory();
                if (localFile.canWrite())
                {
                  BufferedReader localBufferedReader = new BufferedReader(new FileReader(new File(localFile, "mBusData.txt")));
                  str = localBufferedReader.readLine();
                  str = str.split("!i!")[0];
                  localBufferedReader.close();
                }
                Toast.makeText(localContext, localConnection.buy2(str, localConnection.getCategory(str)), 0).show();
                Intent localIntent = new Intent();
                localIntent.setClass(Home.this, Home.class);
                Home.this.startActivity(localIntent);
                Home.this.finish();
                return;
              }
              catch (IOException localIOException)
              {
                Log.e("SD", "Could not read file " + localIOException.getMessage());
                continue;
              }
              Toast.makeText(Home.this.getApplicationContext(), "YOU HAVE ALREADY A VALID TICKET", 0).show();
            }
          }
        };
        localButton1.setOnClickListener(local2);
        return;
      }
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        Log.e("SD", "Could not read file " + localIOException.getMessage());
        continue;
        localImageView.setBackgroundColor(-16777216);
        this.controllo = true;
      }
    }
  }

  public boolean onCreateOptionsMenu(Menu paramMenu)
  {
    super.onCreateOptionsMenu(paramMenu);
    getMenuInflater().inflate(2131099649, paramMenu);
    return true;
  }

  public boolean onOptionsItemSelected(MenuItem paramMenuItem)
  {
    switch (paramMenuItem.getItemId())
    {
    default:
    case 2131165222:
    case 2131165224:
    case 2131165223:
    case 2131165225:
    case 2131165226:
    }
    while (true)
    {
      return true;
      Intent localIntent4 = new Intent();
      localIntent4.setClass(this, Ppage.class);
      startActivity(localIntent4);
      continue;
      exit();
      finish();
      continue;
      Intent localIntent3 = new Intent();
      localIntent3.setClass(this, Option.class);
      startActivity(localIntent3);
      continue;
      Intent localIntent2 = new Intent();
      localIntent2.setClass(this, History.class);
      startActivity(localIntent2);
      continue;
      Intent localIntent1 = new Intent();
      localIntent1.setClass(this, BuyExtra.class);
      startActivity(localIntent1);
    }
  }

  public void onResume()
  {
    super.onResume();
    Button localButton = (Button)findViewById(2131165188);
    ImageView localImageView = (ImageView)findViewById(2131165196);
    String str1 = "";
    TextView localTextView1 = (TextView)findViewById(2131165192);
    TextView localTextView2 = (TextView)findViewById(2131165193);
    Connection localConnection = new Connection();
    localImageView.setBackgroundColor(-16777216);
    try
    {
      File localFile1 = Environment.getExternalStorageDirectory();
      if (localFile1.canWrite())
      {
        File localFile2 = new File(localFile1, "mBusData.txt");
        FileReader localFileReader = new FileReader(localFile2);
        BufferedReader localBufferedReader = new BufferedReader(localFileReader);
        str1 = localBufferedReader.readLine();
        str1 = str1.split("!i!")[0];
        localButton.setText("Buy " + localConnection.getCategory(str1));
        localBufferedReader.close();
      }
      String str2 = localConnection.getValidTicket(str1);
      if (!str2.equals("NO DATA"))
      {
        String[] arrayOfString = str2.split("!i!");
        String str3 = arrayOfString[0];
        String str4 = arrayOfString[1];
        localImageView.setImageBitmap(encodeString(str3));
        Date localDate = new Date();
        Timestamp localTimestamp1 = Timestamp.valueOf(str4);
        Timestamp localTimestamp2 = new Timestamp(localDate.getTime());
        long l = localTimestamp1.getTime() - localTimestamp2.getTime();
        if (this.timeRun)
        {
          this.counter.stop();
          this.counter.cancel();
          this.timeRun = false;
        }
        this.counter = null;
        MyCount localMyCount = new MyCount(l, 1000L);
        this.counter = localMyCount;
        start(timeDisplay);
        timeDisplay.setTextColor(-1);
        this.timeRun = true;
        localTextView1.setText(str3);
        localTextView2.setText("Valid for: ");
        this.controllo = false;
        return;
      }
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        Log.e("SD", "Could not read file " + localIOException.getMessage());
        continue;
        localImageView.setBackgroundColor(-16777216);
        this.controllo = true;
      }
    }
  }

  public void start(View paramView)
  {
    this.counter.start();
    this.timeRun = true;
  }

  public static class MyCount extends CountDownTimer
  {
    public boolean run = false;

    public MyCount(long paramLong1, long paramLong2)
    {
      super(paramLong2);
    }

    public void onFinish()
    {
      this.run = false;
      Home.timeDisplay.setText("Ticket Expired!!");
    }

    public void onTick(long paramLong)
    {
      Home.timeDisplay.setText(Home.formatTime(paramLong));
    }

    public void stop()
    {
      this.run = false;
      Home.timeDisplay.setTextColor(-16777216);
    }
  }
}

/* Location:           C:\Users\Spider22\Desktop\TesiMBUS\classes_dex2jar.jar
 * Qualified Name:     myApp.mobile.Home
 * JD-Core Version:    0.6.1
 */